package com.bookocean.controller;

import com.bookocean.application.common.Result;
import com.bookocean.application.service.DailyQuoteApplicationService;
import com.bookocean.controller.dto.DailyQuoteResultDto;
import com.bookocean.controller.dto.SubmitAnswerDto;

import com.bookocean.controller.dto.UserInfoDto;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 每日一句控制器
 * 
 * @author BookOcean
 * @since 2024-01-01
 */
@RestController
@RequestMapping("/daily-quote")
@RequiredArgsConstructor
public class DailyQuoteController {

    private final DailyQuoteApplicationService dailyQuoteApplicationService;

    /**
     * 获取每日一句
     */
    @PostMapping("/getDailyQuote")
    public Result<DailyQuoteResultDto> getDailyQuote(@Valid @RequestBody UserInfoDto userDto) {
        DailyQuoteResultDto dailyQuote = dailyQuoteApplicationService.getDailyQuote(userDto.getId());
        return Result.success(dailyQuote);
    }

    /**
     * 提交答案
     */
    @PostMapping("/submitAnswer")
    public Result<DailyQuoteResultDto> submitAnswer(@Valid @RequestBody SubmitAnswerDto  submitAnswerDto) {
        DailyQuoteResultDto result = dailyQuoteApplicationService.submitAnswer(
            submitAnswerDto.getId(),
            submitAnswerDto.getUserId(),
            submitAnswerDto.getAnswer()
        );
        return Result.success(result);
    }
}
